package com.boge.modules.shop.service.impl;

import com.boge.modules.shop.entity.CatEntity;
import com.boge.modules.shop.service.CatService;
import com.boge.modules.shop.service.CattypeService;
import com.boge.modules.sys.controller.WebController;
import com.boge.modules.sys.entity.SysUserEntity;
import com.boge.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.Query;

import com.boge.modules.shop.dao.CarDao;
import com.boge.modules.shop.entity.CarEntity;
import com.boge.modules.shop.service.CarService;


@Service("carService")
public class CarServiceImpl extends ServiceImpl<CarDao, CarEntity> implements CarService {

    @Autowired
    private SysUserService userService;


    @Autowired
    private CatService catService;



    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CarEntity> page = this.page(
                new Query<CarEntity>().getPage(params),
                new QueryWrapper<CarEntity>()
        );

        List<CarEntity> records = page.getRecords();
        if(records != null && records.size() > 0){
            for (CarEntity record : records) {
                Integer userId = record.getUserId();
                SysUserEntity user = userService.getById(userId);
                record.setUserName(user.getUsername());

                Integer goodsId = record.getGoodsId();
                if(goodsId !=null){
                    CatEntity catEntity = catService.getById(goodsId);
                    record.setGoodsName(catEntity.getName());
                    record.setPrice(catEntity.getPrice());
                    record.setImg(WebController.BASE_URL+catEntity.getImg());

                }
            }
        }

        return new PageUtils(page);
    }

}